<?php
/**
 * Created by PhpStorm.
 * User: zyw
 * Date: 2018-03-29
 * Time: 16:34
 */

class UserWriteList extends MY_Model{

    public $table = 't_user_white_list';
    public function __construct(){
        parent::__construct();
    }

    /**
     * 获取白名单用户列表
     * @param array $where
     * @param int $page
     * @param int $pagesize
     * @return array
     * @throws Exception
     */
    public function getWriteList($where = array(), $page = 1, $pagesize = 20)
    {
        $sql = "select w.id,w.mobile,w.add_time,u.nickname,u.mobile as u_mobile from ".$this->table." as w left join t_user as u ";
        $sql.= " on w.add_uid=u.uid where 1=1 ";
        foreach($where as $k => $v){
            $sql.= " and w.".$k."=".$v;
        }
        $sql.= " order by add_time desc";

        $index = $page - 1 < 0 ? 0 : ($page - 1) * $pagesize;
        $sql.= " limit ".$index.",".$pagesize;

        return $this->query_sql_list($sql);
    }

    /**
     * 获取白名单用户列表数量
     * @param array $where
     * @return mixed
     * @throws Exception
     */
    public function getWriteListNum($where = array()){
        $sql = "select count(*) as num from ".$this->table." where 1=1 ";
        foreach($where as $k => $v){
            $sql.= " and ".$k."=".$v;
        }
        $num = $this->query_sql_one($sql);
        return $num["num"];
    }
}